package com.huawei.appgallery.forum.user.usercenter.card;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.TextView;
import com.huawei.appgallery.forum.base.card.ForumCard;
import com.huawei.appgallery.forum.base.card.bean.ImageInfo;
import com.huawei.appgallery.forum.base.card.bean.Post;
import com.huawei.appgallery.forum.base.card.bean.PostTime;
import com.huawei.appgallery.forum.base.card.bean.User;
import com.huawei.appgallery.forum.cards.widget.FoldTextView;
import com.huawei.appgallery.forum.cards.widget.PostUserContentView;
import com.huawei.appgallery.forum.comments.api.ICommentDetailResult;
import com.huawei.appgallery.forum.user.usercenter.bean.ForumCommentCardBean;
import com.huawei.appgallery.forum.user.usercenter.widget.CommentReferenceView;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.LineImageView;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import java.util.List;
import o.azb;
import o.bqx;
import o.bse;
import o.bsx;
import o.bsy;
import o.bsy.a;
import o.bsy.c;
import o.bsy.f;
import o.btl;
import o.btu;
import o.bwx;
import o.bxc;
import o.cbb.b;
import o.cbb.e;
import o.cbb.j;
import o.cbu;
import o.ccc;
import o.cgz;
import o.chy;
import o.cil;
import o.cim;
import o.dof;
import o.eqx;
import o.evx;
import o.fho;
import o.fjc;
import o.fjo;
import o.fjq;
import o.fke;
import o.fkg;
import o.ll;

public class ForumCommentCard extends ForumCard implements OnClickListener, btl {
    private TextView ʻ;
    private PostUserContentView ʻॱ;
    private LineImageView ʼ;
    private TextView ʽ;
    private Context ˊ;
    private LinearLayout ˊॱ;
    private FoldTextView ˋ;
    private LinearLayout ˋॱ;
    private CommentReferenceView ˎ;
    private String ˏ = "ForumCommentCard";
    private PopupMenu ˏॱ;
    private TextView ͺ;
    private ForumCommentCardBean ॱ;
    private String ॱˊ;
    private long ॱˋ;
    private int ॱˎ;
    private ImageView ॱॱ;
    private User ॱᐝ;
    private TextView ᐝ;
    private fjc ᐝॱ = new fjc<ICommentDetailResult>(this) {
        final /* synthetic */ ForumCommentCard ˊ;

        {
            this.ˊ = r1;
        }

        public void ˎ(int i, ICommentDetailResult iCommentDetailResult) {
            if (i == -1 && iCommentDetailResult != null) {
                this.ˊ.ॱ.ˎ(iCommentDetailResult.getLike() ? 1 : 0);
                if (iCommentDetailResult.getLikeCount() >= 0) {
                    this.ˊ.ॱ.ˊॱ().ˋ(iCommentDetailResult.getLikeCount());
                }
                this.ˊ.ॱ.ˊॱ().ˎ((long) iCommentDetailResult.getReplyCount());
                this.ˊ.ʻ();
            }
        }
    };

    public ForumCommentCard(Context context) {
        super(context);
        this.ˊ = context;
    }

    public cgz ˏ(View view) {
        ʽ(view);
        this.ʻॱ = (PostUserContentView) view.findViewById(b.ˊॱ);
        this.ʻॱ.setUserContentClickLisenter(this);
        azb.ˏ(view, b.ˊʻ);
        this.ˎ = (CommentReferenceView) view.findViewById(b.ʻ);
        azb.ˏ(this.ˎ);
        this.ˋ = (FoldTextView) view.findViewById(b.ʹ);
        this.ʼ = (LineImageView) view.findViewById(b.ﹳ);
        this.ʽ = (TextView) view.findViewById(b.ㆍ);
        this.ॱॱ = (ImageView) view.findViewById(b.ᐝˊ);
        this.ᐝ = (TextView) view.findViewById(b.ᐧ);
        this.ʻ = (TextView) view.findViewById(b.ꞌ);
        this.ͺ = (TextView) view.findViewById(b.ʻॱ);
        this.ˊॱ = (LinearLayout) view.findViewById(b.ॱˎ);
        ((LinearLayout) view.findViewById(b.ʻˊ)).setOnClickListener(this);
        ((LinearLayout) view.findViewById(b.ꜞ)).setOnClickListener(this);
        this.ʽ.setOnClickListener(this);
        this.ʼ.setOnClickListener(this);
        this.ˋ.setOnClickListener(this);
        this.ˋॱ = (LinearLayout) view.findViewById(c.ᐝˋ);
        this.ˋॱ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ ForumCommentCard ˋ;

            {
                this.ˋ = r1;
            }

            public void onClick(View view) {
                if (this.ˋ.ˏॱ != null) {
                    this.ˋ.ˏॱ.show();
                }
            }
        });
        return this;
    }

    private void ˎ() {
        this.ˏॱ = new PopupMenu(this.ˊ, this.ˋॱ);
        if (this.ˊ instanceof Activity) {
            ((Activity) this.ˊ).getMenuInflater().inflate(f.ॱ, this.ˏॱ.getMenu());
            this.ˏॱ.getMenu().findItem(c.ॱ).setVisible(false);
            this.ˏॱ.setOnMenuItemClickListener(new OnMenuItemClickListener(this) {
                final /* synthetic */ ForumCommentCard ˋ;

                {
                    this.ˋ = r1;
                }

                public boolean onMenuItemClick(MenuItem menuItem) {
                    this.ˋ.ˎ(menuItem);
                    return false;
                }
            });
        }
    }

    private void ˎ(MenuItem menuItem) {
        if (this.ॱ != null && this.ॱ.ˊॱ() != null) {
            ((bwx) fho.ˏ().ˋ("Operation").ॱ(bwx.class)).ˏ(this.ˊ, this.ॱ.ˊॱ().ˏ(), this.ॱ.ॱ()).ˏ(new fjq<Boolean>(this) {
                final /* synthetic */ ForumCommentCard ˎ;

                {
                    this.ˎ = r1;
                }

                public void onComplete(fjo<Boolean> o_fjo_java_lang_Boolean) {
                    if (o_fjo_java_lang_Boolean.ˊ() && ((Boolean) o_fjo_java_lang_Boolean.ॱ()).booleanValue()) {
                        Intent intent = new Intent("com.huawei.appgallery.forum.posts.deletecomment");
                        intent.putExtra("comment_id", this.ˎ.ॱ.ˊॱ().ˏ());
                        ll.ˏ(this.ˎ.ˊ).ˋ(intent);
                    }
                }
            });
            this.ˏॱ.dismiss();
        }
    }

    public void ˏ(CardBean cardBean) {
        if (cardBean instanceof ForumCommentCardBean) {
            ForumCommentCardBean forumCommentCardBean = (ForumCommentCardBean) cardBean;
            this.ॱ = forumCommentCardBean;
            this.ॱˎ = forumCommentCardBean.ˋॱ();
            ˊ(forumCommentCardBean.ˊॱ(), forumCommentCardBean.ʼ());
            if (forumCommentCardBean.ʽ() != null) {
                this.ॱᐝ = forumCommentCardBean.ʽ();
                ˎ(forumCommentCardBean.ʽ(), forumCommentCardBean.ˊॱ().ˎ());
            }
            this.ˎ.setReference(forumCommentCardBean.ͺ());
            this.ˎ.setDomain(forumCommentCardBean.ॱ());
            if (this.ॱ.ʽ().ʼ()) {
                this.ˋॱ.setVisibility(0);
                ˎ();
            } else {
                this.ˋॱ.setVisibility(8);
            }
            if (forumCommentCardBean.ͺ() != null) {
                String ʽ = forumCommentCardBean.ͺ().ʽ();
                if (!TextUtils.isEmpty(ʽ) && ʽ.contains(HiAnalyticsConstant.REPORT_VAL_SEPARATOR) && ʽ.length() >= 2) {
                    Object substring = ʽ.substring(ʽ.lastIndexOf(HiAnalyticsConstant.REPORT_VAL_SEPARATOR) + 1);
                    if (!TextUtils.isEmpty(substring)) {
                        this.ॱˋ = Long.parseLong(substring);
                    }
                }
            }
        }
    }

    private void ˎ(User user, PostTime postTime) {
        this.ʻॱ.setData(user, postTime);
    }

    private void ˊ(Post post, boolean z) {
        if (post == null) {
            this.ʽ.setVisibility(8);
            this.ˋ.setVisibility(8);
            this.ˊॱ.setVisibility(0);
            this.ͺ.setText(bse.ˏ.ॱ(400012).ˎ());
            return;
        }
        ʻ();
        ˋ(post);
        this.ˊॱ.setVisibility(8);
        if (post.ॱˊ() == 0) {
            ˎ(post, z);
        } else if (post.ॱˊ() == 2) {
            ॱ(post, z);
            this.ͺ.setText(j.ॱ);
        } else if (post.ॱˊ() == 3) {
            ॱ(post, z);
            if (this.ॱˎ == 1) {
                this.ͺ.setText(j.ॱॱ);
            } else if (this.ॱˎ == 2 || this.ॱˎ == 3) {
                this.ͺ.setText(j.ʼ);
            } else if (this.ॱˎ == 0) {
                this.ͺ.setText(j.ॱॱ);
            }
        } else if (post.ॱˊ() == 4) {
            ॱ(post, z);
            if (this.ॱˎ == 1) {
                this.ͺ.setText(j.ᐝ);
            } else if (this.ॱˎ == 2 || this.ॱˎ == 3) {
                this.ͺ.setText(j.ʻ);
            }
        } else if (post.ॱˊ() == 1) {
            ॱ(post, z);
            this.ͺ.setText(bse.ˏ.ॱ(400006).ˎ());
        }
    }

    private void ˎ(Post post, boolean z) {
        this.ॱˊ = cbu.ˋ(post.ॱ());
        if (ॱ(post) && TextUtils.isEmpty(this.ॱˊ)) {
            this.ॱˊ = this.ˊ.getString(j.ʽ);
        }
        if (z) {
            ˊ(post, this.ॱˊ, true);
            this.ʽ.setText(this.ˊ.getResources().getString(j.ॱᐝ));
            return;
        }
        ˊ(post, this.ॱˊ, false);
        this.ʽ.setText(this.ˊ.getResources().getString(j.ˋˋ));
        this.ʼ.setVisibility(8);
    }

    private void ॱ(Post post, boolean z) {
        this.ˊॱ.setVisibility(0);
        ˎ(post, z);
        if (this.ॱᐝ != null && this.ॱᐝ.ˊ() == 0) {
            this.ʽ.setVisibility(8);
            this.ˋ.setVisibility(8);
            this.ʼ.setVisibility(8);
        }
    }

    private boolean ॱ(Post post) {
        List ॱॱ = post.ॱॱ();
        if (ॱॱ == null || ॱॱ.size() <= 0) {
            return false;
        }
        if (dof.ʽ(((ImageInfo) ॱॱ.get(0)).ˋ()) && dof.ʽ(((ImageInfo) ॱॱ.get(0)).ˊ())) {
            return false;
        }
        return true;
    }

    private void ˋ(Post post) {
        List ॱॱ = post.ॱॱ();
        if (ॱ(post)) {
            String ˊ;
            this.ʼ.setVisibility(0);
            if (TextUtils.isEmpty(((ImageInfo) ॱॱ.get(0)).ˋ())) {
                ˊ = ((ImageInfo) ॱॱ.get(0)).ˊ();
            } else {
                ˊ = ((ImageInfo) ॱॱ.get(0)).ˋ();
            }
            int ॱ = (int) (((float) ((azb.ॱ(ˉ().getContext()) - azb.ˏ(this.ˊ)) - azb.ᐝ(this.ˊ))) - ˉ().getContext().getResources().getDimension(e.ˋॱ));
            ˏ(this.ʼ, ॱ, ˊ, ((ImageInfo) ॱॱ.get(0)).ˎ(), ((ImageInfo) ॱॱ.get(0)).ˏ());
            LayoutParams layoutParams = this.ʼ.getLayoutParams();
            if (layoutParams.height > 4096) {
                this.ʼ.setScaleType(ScaleType.FIT_START);
                layoutParams.height = 4096;
                this.ʼ.setLayoutParams(layoutParams);
            }
            if (bsx.ˎ(ˊ)) {
                bsx.ˊ(this.ʼ, ˊ);
                return;
            } else {
                eqx.ˎ(this.ʼ, ˊ);
                return;
            }
        }
        this.ʼ.setVisibility(8);
    }

    private void ˏ(ImageView imageView, int i, String str, int i2, int i3) {
        Object obj = null;
        if (bsx.ˎ(str)) {
            obj = 1;
        }
        LayoutParams layoutParams = imageView.getLayoutParams();
        if (i2 <= 0 || i3 <= 0) {
            layoutParams.width = i;
            layoutParams.height = (int) (0.5f * ((float) i));
        } else {
            float f = ((float) i3) / ((float) i2);
            if (obj == null) {
                layoutParams.width = i;
                layoutParams.height = (int) (((float) i) * f);
            } else if (i2 < i) {
                layoutParams.width = i2;
                layoutParams.height = (int) (((float) i2) * f);
            } else {
                layoutParams.width = i;
                layoutParams.height = (int) (((float) i) * f);
            }
        }
        imageView.setLayoutParams(layoutParams);
    }

    private void ˊ(Post post) {
        CharSequence string;
        long ʻ = post.ʻ();
        long ʼ = post.ʼ();
        if (ʻ <= 0) {
            string = this.ˊ.getString(bsy.j.ˋॱ);
        } else if (ʻ > 999) {
            string = "999+";
        } else {
            string = String.valueOf(ʻ);
        }
        this.ᐝ.setText(string);
        if (ʼ <= 0) {
            string = this.ˊ.getString(bsy.j.ͺ);
        } else if (ʼ > 999) {
            string = "999+";
        } else {
            string = String.valueOf(ʼ);
        }
        this.ʻ.setText(string);
    }

    public void onClick(View view) {
        if (view.getId() == b.ﹳ || view.getId() == b.ʹ) {
            ʽ();
        } else if (view.getId() == b.ʻˊ) {
            if (cbu.ˎ(this.ˊ, this.ॱ) && cbu.ॱ(this.ˊ, this.ॱ)) {
                Post ˊॱ = this.ॱ.ˊॱ();
                if (this.ॱˎ == 2 || this.ॱˎ == 3) {
                    ccc.ˋ().ॱ(this.ˊ, this.ॱ.ʽ(), this.ॱˎ, this.ॱˋ, ˊॱ.ॱˊ(), this.ॱ.ॱ(), this.ॱ.ˊ());
                } else {
                    ccc.ˋ().ॱ(this.ˊ, this.ॱ.ʽ(), this.ॱˎ, ˊॱ.ˏ(), ˊॱ.ॱˊ(), this.ॱ.ॱ(), this.ॱ.ˊ());
                }
            }
        } else if (view.getId() == b.ꜞ) {
            if (cbu.ˎ(this.ˊ, this.ॱ) && cbu.ॱ(this.ˊ, this.ॱ)) {
                ʼ();
            }
        } else if (view.getId() == b.ㆍ) {
            if (this.ॱ.ʼ()) {
                this.ॱ.ˋ(false);
                this.ʽ.setText(this.ˊ.getResources().getString(j.ˋˋ));
                ˋ(this.ॱ.ˊॱ());
                this.ʼ.setVisibility(8);
            } else {
                this.ॱ.ˋ(true);
                this.ʽ.setText(this.ˊ.getResources().getString(j.ॱᐝ));
                ˋ(this.ॱ.ˊॱ());
            }
            this.ˋ.ˎ();
        }
    }

    private void ʼ() {
        final int i = this.ॱ.ᐝ() ? 1 : 0;
        ((bwx) fho.ˏ().ˋ("Operation").ॱ(bwx.class)).ˊ(this.ˊ, this.ॱ.ˊॱ().ॱˊ(), 1, this.ॱ.ˊॱ().ˏ(), i, this.ॱ.ॱ(), this.ॱ.ˊ()).ˏ(new fke<bxc>(this) {
            final /* synthetic */ ForumCommentCard ˎ;

            public void ˎ(fkg o_fkg) {
            }

            public void ॱ(bxc o_bxc) {
                if (o_bxc.ˏ() == 9 && o_bxc.ˎ()) {
                    bqx.ˏ(this.ˎ.ˏ, "AUTHENTION_ACCESS is ok");
                    this.ˎ.ˊ(i);
                } else if (o_bxc.ˏ() == 0 && o_bxc.ˎ()) {
                    bqx.ˏ(this.ˎ.ˏ, "response is ok");
                } else if (o_bxc.ˏ() == -1 && !o_bxc.ˎ()) {
                    bqx.ˏ(this.ˎ.ˏ, "response is fail");
                    if (i == 1) {
                        this.ˎ.ˊ(0);
                    } else {
                        this.ˎ.ˊ(1);
                    }
                }
            }

            public void ˊ(Exception exception) {
            }

            public void ॱ() {
            }
        });
    }

    private void ˊ(int i) {
        long ʻ = this.ॱ.ˊॱ().ʻ();
        if (i == 1) {
            this.ॱ.ˎ(0);
            if (ʻ > 0) {
                this.ॱ.ˊॱ().ˋ(ʻ - 1);
            }
        } else {
            this.ॱ.ˎ(1);
            this.ॱ.ˊॱ().ˋ(ʻ + 1);
        }
        ʻ();
    }

    private void ʻ() {
        ˊ(this.ॱ.ˊॱ());
        if (this.ॱ.ᐝ()) {
            this.ॱॱ.setImageResource(a.ॱ);
        } else {
            this.ॱॱ.setImageResource(a.ˎ);
        }
    }

    public void ʽॱ() {
        if (this.ॱᐝ != null) {
            ccc.ˋ().ॱ(this.ˊ, this.ॱᐝ.ॱ(), this.ॱᐝ.ˊ(), this.ॱ.ॱ());
        }
    }

    public void ॱ(boolean z) {
        ʽ();
    }

    public void ॱ(chy o_chy) {
        View ˉ = ˉ();
        if (ˉ != null) {
            ˉ.setOnClickListener(new evx(this) {
                final /* synthetic */ ForumCommentCard ˎ;

                {
                    this.ˎ = r1;
                }

                public void ˋ(View view) {
                    this.ˎ.ॱ(false);
                }
            });
        }
    }

    private void ˊ(final Post post, String str, boolean z) {
        this.ˋ.setOnContentChangedListener(new FoldTextView.e(this) {
            final /* synthetic */ ForumCommentCard ॱ;

            public void ˎ(boolean z) {
                if (this.ॱ.ॱ(post) || z) {
                    this.ॱ.ʽ.setVisibility(0);
                } else {
                    this.ॱ.ʽ.setVisibility(8);
                }
            }
        });
        this.ˋ.setMovementMethod(LinkMovementMethod.getInstance());
        this.ˋ.setContent(btu.ॱ(this.ˊ, str, btu.ˏ()), z, ((azb.ॱ(this.ˊ) - this.ˊ.getResources().getDimensionPixelSize(e.ˋॱ)) - azb.ᐝ(this.ˊ)) - azb.ˏ(this.ˊ));
    }

    private void ʽ() {
        if (this.ॱ != null && this.ॱ.ˊॱ() != null) {
            cil.ˋ(this.ˊ, new cim.a().ˊ(this.ॱ.ˊॱ().ͺ()).ˋ());
            ccc.ˋ().ˋ(this.ˊ, this.ॱ.ˊॱ().ͺ(), this.ॱ.ॱ(), this.ᐝॱ);
        }
    }
}
